package com.love.marriage.permissionInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Insert;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.permissionInfo.service.PermissionInfoService;
import com.love.marriage.permissionInfo.vo.PermissionInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

;

/**
 * description:  权限信息表restApi
 * author:       majf
 * createDate:   2024-01-16 15:43:56
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "权限信息表相关接口", description = "权限信息表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/permission-info")
public class PermissionInfoController {

    private final PermissionInfoService permissionInfoService;

    @ApiOperationSupport(order = 10, author = "majf")
    @Operation(summary = "获取权限信息表分页", description = "获取权限信息表分页")
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(description = "页码", name = "pageNum", schema = @Schema(type = "Integer", example = "1")),
            @Parameter(description = "每页大小", name = "pageSize", schema = @Schema(type = "Integer", example = "10")),
            @Parameter(description = "查询条件", name = "permissionInfoVo", schema = @Schema(type = "PermissionInfoVo"))}
    )
    public Result<Page<PermissionInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                  @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                  @RequestBody(required = false) PermissionInfoVo permissionInfoVo) {
        return Result.success(permissionInfoService.getPage(pageNum, pageSize, permissionInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "majf")
    @Operation(summary = "获取权限信息表详情", description = "获取权限信息表详情")
    @GetMapping
    public Result<PermissionInfoVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(permissionInfoService.queryPermissionInfo(id));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "majf")
    @Operation(summary = "新增权限信息表", description = "新增权限信息表")
    @PostMapping
    public Result<PermissionInfoVo> add(@Validated({Insert.class}) @RequestBody PermissionInfoVo permissionInfoVo) {
        return Result.success(permissionInfoService.addPermissionInfo(permissionInfoVo));
    }

    @ApiOperationSupport(order = 40, author = "majf")
    @Operation(summary = "修改权限信息表", description = "修改权限信息表")
    @PutMapping
    public Result<PermissionInfoVo> update(@Validated({Update.class}) @RequestBody PermissionInfoVo permissionInfoVo) {
        return Result.success(permissionInfoService.updatePermissionInfo(permissionInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "majf")
    @Operation(summary = "刪除权限信息表", description = "刪除权限信息表")
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(permissionInfoService.deletePermissionInfo(ids));
    }

    @ApiOperationSupport(order = 60, author = "alex")
    @Operation(summary = "获取权限管理列表", description = "获取权限管理列表")
    @PostMapping(value = "/list")
    public Result<List<PermissionInfoVo>> getList(@RequestBody(required = false) PermissionInfoVo permissionInfoVo) {
        return Result.success(permissionInfoService.getList(permissionInfoVo));
    }
}
